package br.com.dev.tcc.view.apolice;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import br.com.dev.tcc.R;
import br.com.dev.tcc.adapter.ListaApolicesLembretesAdapter;
import br.com.dev.tcc.adapter.ListaApolicesLembretesAdapter.OnAlarmModifiedListener;
import br.com.dev.tcc.bean.Apolice;

public class ListaPreferenciasView {

	private Context ctx;
	private ListView list;
	private TextView tvNoItens;
	private View progressBar;

	public ListaPreferenciasView(Activity activity) {

		ctx = activity;
		list = (ListView) activity.findViewById(R.id.list);
		tvNoItens = (TextView) activity.findViewById(R.id.tvNoItens);
		progressBar = activity.findViewById(R.id.progressBar);
		
		tvNoItens.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {

				ctx.startActivity(new Intent(ctx, ApolicesActivity.class));
			}
		});
	}

	public void setItens(List<Apolice> itens) {

		list.setVisibility(View.VISIBLE);
		tvNoItens.setVisibility(View.GONE);
		list.setAdapter(new ListaApolicesLembretesAdapter(ctx, itens, new OnAlarmModifiedListener() {
			
			@Override
			public void onModify() {

				progressBar.setVisibility(View.VISIBLE);
			}
			
			@Override
			public void onFinishModify() {
				
				progressBar.setVisibility(View.GONE);
			}
		}));
	}

	public void setListener(OnItemClickListener listener) {

		list.setOnItemClickListener(listener);
	}

	public void hideList() {

		list.setVisibility(View.GONE);
		tvNoItens.setVisibility(View.VISIBLE);
	}
}
